const express = require('express')
const { Article } = require('../models/article')

const router = express.Router()

router.post('/add', express.json(), async (req, res) => {
  const article = await Article.create(req.body)
  res.send({ code: 0, msg: 'ok', data: article })
})

router.get('/:id', async (req, res) => {
  const article = await Article.findOne({ where: { id: +req.params.id }, include: 'User' })
  res.send({ code: 0, msg: 'ok', data: article })
})

module.exports = {
  router
}